<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>表单验证</title>
		<script src="../js/jquery-3.4.1.min.js"></script>
		<script>
			$(function() {
				$("form").submit(function() {
					var r = $("input[name='like']:checked").length;
					//var r = $(":checkbox[name='like']:checked").length;
					if (r < 2) {
						alert("至少要选两个");
						return false;
					}
					return true;
				});

			});
		</script>
	</head>
	<body>
		<h1>云豆网注册</h1>
		<form action="reg.html" method="get">
			<fieldset>登录名
				<input type="text" name="loginname" placeholder="登录名" required pattern="\w{2,30}" />
			</fieldset>
			<fieldset>密码
				<input type="password" name="pass" placeholder="密码" required pattern="\S{6,30}" />
			</fieldset>
			<fieldset>
				爱好（至少选择两个）:
				<input type="checkbox" name="like" value="sing" />唱歌
				<input type="checkbox" name="like" value="dance" />跳舞
				<input type="checkbox" name="like" value="Rap" />说唱
				<input type="checkbox" name="like" value="baseketball" />篮球
				<input type="checkbox" name="like" value="Study" />学习
				<span id="LikeTip"></span>
			</fieldset>
			<fieldset>
				请勾选同意我们的<a href="#">用户协议</a><input type="checkbox" name="accpet" required />
			</fieldset>
			<p>
				<input type="submit" value="注册" />
			</p>
		</form>
	</body>
</html>
